<template>
  <div class="mod-user">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="pageIndex = 1;getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.userName" placeholder="学号或用户名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="pageIndex = 1;getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        prop="username"
        header-align="center"
        align="center"
        label="学号">
      </el-table-column>
      <el-table-column
        prop="nickname"
        header-align="center"
        align="center"
        label="用户名">
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        label="历史成绩统计详情">
        <template slot-scope="scope">
          <span class="detail" style="cursor: pointer;text-decoration: underline;color: #17B3A3;" @click="detail(scope.row.userId)">详情</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="loginTime"
        header-align="center"
        align="center"
        label="最近一次登录">
      </el-table-column>
      <el-table-column
        prop="fireClassroomMax"
        header-align="center"
        align="center"
        label="教室火灾最好成绩">
      </el-table-column>
      <el-table-column
        prop="earthClassroomMax"
        header-align="center"
        align="center"
        label="教室地震最好成绩">
      </el-table-column>
      <el-table-column
        prop="fireDormMax"
        header-align="center"
        align="center"
        label="宿舍火灾最好成绩">
      </el-table-column>
      <el-table-column
        prop="earthDormMax"
        header-align="center"
        align="center"
        label="宿舍地震最好成绩">
      </el-table-column>
      <el-table-column
        prop="fireTrainingMax"
        header-align="center"
        align="center"
        label="实训楼火灾最好成绩">
      </el-table-column>
      <el-table-column
        prop="earthTrainingMax"
        header-align="center"
        align="center"
        label="实训楼地震最好成绩">
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗 -->
    <exam-detail v-if="examDetailVisible" ref="examDetail"></exam-detail>
  </div>
</template>

<script>
  import ExamDetail from './detail'
  export default {
    data () {
      return {
        dataForm: {
          userName: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        examDetailVisible: false
      }
    },
    components: {
      ExamDetail
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/ed/exam/user-score-list'),
          method: 'get',
          params: this.$http.adornParams({
            'current': this.pageIndex,
            'size': this.pageSize,
            'key': this.dataForm.userName
          })
        }).then(({data}) => {
          if (data && data.code === '0') {
            this.dataList = data.data.records
            this.totalPage = data.data.total
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 详情
      detail (id) {
        this.examDetailVisible = true
        this.$nextTick(() => {
          this.$refs.examDetail.init(id)
        })
      }
    }
  }
</script>
